import React from 'react';

import './header.scss';

import PropTypes from 'prop-types';
 class   Header extends React.Component{
  constructor(props){
    super(props)
    this.state={
    }
     this.leftButtonAction=this.leftButtonAction.bind(this)
     this.rightButtonAction=this.rightButtonAction.bind(this)
 }
 static propTypes={
   title:PropTypes.string,
   rightButtonView:PropTypes.element,
   isBack:PropTypes.bool,
   rightButtonAction:PropTypes.func
  }
  static defaultProps = {
    title:"公务用车",
    isBack:false,
    rightButtonView:null
  }
  leftButtonAction(){
    if(this.props.isBack)
     this.props.history.goBack()
  }
  rightButtonAction(){
    this.props.rightAction()
  }
  render(){
    
    return (
      <div className="header">
           <div onClick={this.leftButtonAction} className={["header-button",this.props.isBack?"back-button":"left-button"].join("  ")}>
               <a href="javascript:;"></a>
           </div>
           <h2 className="header-center">{this.props.title}</h2>
           {this.props.rightButtonView&&this.props.rightButtonView!=null?<div onClick={this.rightButtonAction} className="header-button">
                 {this.props.rightButtonView}
          </div>:null}
      </div>
    );
  }
}


export default Header;